package com.alpaak.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: ThreadContext
 * @Description: ThreadContext 是基于 ThreadLocal 来存储参数的一个工具类
 * @author: FengWenJu
 * @date: 2017年11月7日 下午1:22:36
 */
public class ThreadContext {
	private static ThreadLocal<Map<String, Object>> context_local = new ThreadLocal<Map<String, Object>>() {
		protected Map<String, Object> initialValue() {
			return new HashMap<String, Object>();
		};
	};
	
	private static ThreadContext context = new ThreadContext();
	
	private ThreadContext(){
	}
	
	public static ThreadContext getContext(){
		return context;
	}
	
	public boolean put(String key, Object value){
		context_local.get().put(key, value);
		return true;
	}
	
	public Object get(String key){
		return context_local.get().get(key);
	}
	
	public Object remove(String key){
		return context_local.get().remove(key);
	}

	public void clear(){
		context_local.get().clear();
	}
}
